package com.lancoo.edu.platform.operation.backupRestore.controller;

import com.lancoo.edu.platform.operation.backupRestore.service.bo.BrBackupBoService;
import com.lancoo.edu.platform.operation.commons.annotation.CheckToken;
import com.lancoo.edu.platform.operation.commons.controller.base.BaseResultController;
import com.lancoo.edu.platform.operation.commons.dto.BaseResult;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author lzh
 * @Date 2024/3/25 11:42
 * @description 数据备份控制器
 */
@RestController
@RequestMapping("/api/backupRestore/backup")
@AllArgsConstructor
@Validated
public class BrBackupController extends BaseResultController {

    private final BrBackupBoService brBackupBoService;

    /**
     * 主动备份功能
     *
     * @param eduId       教育局ID
     * @param sysId       系统ID
     * @return 返回
     */
    @PostMapping("/single")
    @CheckToken
    public BaseResult backup(@NotBlank(message = "教育局ID不能为空") String eduId,
                             @NotBlank(message = "系统ID不能为空") String sysId){
        // brBackupBoService.backup(eduId, sysId);
        brBackupBoService.backupSingle(eduId, sysId);
        return success();
    }

    /**
     * 主动备份功能（全部）
     *
     * @param eduId    教育局ID
     * @return 返回
     */
    @PostMapping("/all")
    @CheckToken
    public BaseResult backupAll(@NotBlank(message = "教育局ID不能为空") String eduId) {
        brBackupBoService.backupAll(eduId);
        return success();
    }
}
